package com.bjpowernode.boss.util;

import jakarta.annotation.Resource;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.Map;
import java.util.concurrent.TimeUnit;
//redis操作类，存储token，防止redis崩掉
@Component
public class RedisClient {
    //字符串序列化类
    @Resource
    private StringRedisTemplate stringRedisTemplate;

    //使用hash类型，存储jwt，loginId，过期时间
    public boolean addAllHash(String key, Map<String ,String> data, int timeout,TimeUnit timeUnit){
        //设置过期时间返回布尔值
        boolean flag = true;
        //将数据放入map
        stringRedisTemplate.opsForHash().putAll(key, data);
        //设置过期时间
        if (timeout >0){
            flag = stringRedisTemplate.expire(key, timeout, timeUnit);
        }
        return flag;
    }
}
